package com.emmmya.ocs.modules.system.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.emmmya.ocs.common.base.BaseEntity;
import lombok.Data;
import lombok.ToString;

import javax.persistence.*;
import java.util.List;

@Data
@Entity
@TableName("h_permissions")
@Table(name = "h_permissions")
@JsonIgnoreProperties(value={"roles"})
@ToString
public class Permissions extends BaseEntity {
    @Column(name = "permissions_name")
    @TableField("permission_name")
    private String permissionName;

    @Column(name = "permissions_code")
    @TableField("permission_code")
    private String permissionCode;

    @Column(name = "level")
    @TableField("level")
    private Integer level;

    @Column(name="parent_id")
    @TableField("parent_id")
    private Long parentId;

    @ManyToMany(
            cascade = CascadeType.REFRESH,
            fetch = FetchType.LAZY)
    @JoinTable(name = "h_role_permission",//关联表
            inverseJoinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "id")}, //关联表名
            joinColumns = {@JoinColumn(name = "permission_id",referencedColumnName = "id")})//维护端外键
    @JsonBackReference
    @JsonIgnore //json解析过滤此项
    @TableField(exist = false)
    private List<Role> roles;


    @Override
    public String toString() {
        return "Permissions{" +
                "permissionName='" + permissionName + '\'' +
                ", level='" + level + '\'' +
                '}';
    }
}
